using IQIGame.Onigao.Framework.Editors;
using Sirenix.OdinInspector.Editor;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    public enum EntityAnimEventType
    {
        None = 0,
        ActiveObject = 1,
        DeactiveObject = 2,
        ActiveEffect = 3,
        DeactiveEffect = 4,
        PlayAudio = 5,
        PlayFootStep = 6,
    }

    [Serializable]
    public class EntityAnimConfig
    {
        public string animtionName;

        public List<EntityAnimEvent> entityAnimEvents = new List<EntityAnimEvent>();

        [Serializable]
        public class EntityAnimEvent
        {
            public float time;
            public EntityAnimEventType eventType;
            public int intArg;

            public string GetEventFunctionName()
            {
                switch (eventType)
                {
                    case EntityAnimEventType.None:
                        return string.Empty;
                    case EntityAnimEventType.ActiveObject:
                        return "ActiveObject";
                    case EntityAnimEventType.DeactiveObject:
                        return "DeactiveObject";
                    case EntityAnimEventType.ActiveEffect:
                        return "ActiveObject";
                    case EntityAnimEventType.DeactiveEffect:
                        return "DeactiveObject";
                    default:
                        return eventType.ToString();
                }
                //return string.Empty;
            }
        }

        public class EntityAnimEventDrawer : OdinValueDrawer<EntityAnimEvent>
        {
            protected override void DrawPropertyLayout(GUIContent label)
            {
                // 获取属性的引用
                var entry = this.ValueEntry;
                var property = this.Property;
                var variable = entry.SmartValue;

                EditorGUILayout.BeginVertical();

                EditorGUILayout.LabelField(property.Index.ToString(), EditorBindingUtil.IndexTextStyle, GUILayout.Width(30));
                variable.eventType = (EntityAnimEventType)EditorGUILayout.EnumPopup("类型:", variable.eventType);
                variable.time = EditorGUILayout.FloatField("动画时间点:", variable.time);
                switch (variable.eventType)
                {
                    case EntityAnimEventType.None:
                        break;
                    case EntityAnimEventType.ActiveObject:
                    case EntityAnimEventType.DeactiveObject:
                        variable.intArg = EditorGUILayout.IntField("Object索引:", variable.intArg);
                        break;
                    case EntityAnimEventType.ActiveEffect:
                    case EntityAnimEventType.DeactiveEffect:
                        variable.intArg = EditorGUILayout.IntField("绑定特效索引:", variable.intArg);
                        break;
                    case EntityAnimEventType.PlayAudio:
                        variable.intArg = EditorGUILayout.IntField("音效id:", variable.intArg);
                        break;
                    case EntityAnimEventType.PlayFootStep:
                        break;
                }

                EditorGUILayout.EndVertical();

                // 更新属性的值
                this.ValueEntry.SmartValue = variable;
            }
        }
    }


}
